<template>
  <div class="shopping-content">
    <div class="shopping-list">
      <van-nav-bar
        title="购物车"
        @click-left="onClickLeft"
        @click-right="onClickRight"
      >
        <template #left>
          <van-icon name="home-o" size="20px" color="#fff" />
        </template>
        <template #right>
          <van-popover
            v-model="showPopover"
            trigger="click"
            :actions="actions"
            placement="bottom-end"
          >
            <template #reference>
              <van-button type="primary">
                <van-icon name="ellipsis" size="20px" color="#fff" />
              </van-button>
            </template>
          </van-popover>
        </template>
      </van-nav-bar>
    </div>
    <!-- 第二栏  3个100%  未登录时的状态 -->
    <div class="shopping-con-title">
      <div class="shopping-title">
        <span><van-icon name="passed" color="#fff" />100%正品保证</span>
        <span><van-icon name="passed" color="#fff" />100%所有商品精选细挑</span>
        <span><van-icon name="passed" color="#fff" />100%售后无忧</span>
      </div>
      <span class="number"
        ><b>购物数量</b><em>{{ count.count }}</em></span
      >
    </div>
    <!-- 购物车热门推荐 @click 跳转到详情页-->
    <div class="cart-logo" >
      <img src="https://java.crmeb.net/static/img/noCart.b918148e.png" alt="" />
    </div>
    <div class="hot-comment">
      <div class="hot-title">
        <p>热门推荐</p>
      </div>
      <div class="hot-display">
        <div class="hot-display-con" v-for="item in product" :key="item.id" @click="toDetails(item.id)">
          <img :src="item.image" alt="" />
          <div class="price">
            <p>{{ item.storeName }}</p>
            <span><em>￥</em>{{ item.price }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "ShoppingCartView",

  data() {
    return {
      showPopover: false,
      actions: [
        { text: "首页", icon: "add-o" },
        { text: "搜索", icon: "search" },
        { text: "我的收藏", icon: "star-o" },
        { text: "个人中心", icon: "home-o" },
      ],
      product: [], // 热门推荐
      count: [], // 购物数量
      infoId:null,  // 详情页
    };
  },

  methods: {
    onClickLeft() {
      this.$router.replace({
        name: "IndexVue",
      });
    },
    onClickRight() {},
    // 点击某个商品信息跳转详情页
    toDetails(id){
        this.infoId = id;
        console.log(this.infoId);
        this.$router.push(`/ProductDetails/?id=${this.infoId}`)
    }
  },

  async created() {
    const token = sessionStorage.getItem("token") || undefined; // 声明token
    if (token) {
      await this.$requestTools(
        "/crmeb/cart/count?numType=true&type=sum",
        "GET",
        {
          headers: {
            "authori-zation": token,
          },
        }
      ).then((data) => {
        this.count = data.data.data;
        // console.log(this.count);
      });
    }

    // 热门推荐
    const {
      data: {
        data: { list },
      },
    } = await this.$requestTools("/crmeb/index/product/1", "GET", {
      params: {
        page: 1,
        limit: 10,
      },
    });
    this.product = list;
    // console.log(this.product);
  },
};
</script>

<style lang="scss" scoped>
.shopping-content {
  height: 100vh;
  overflow-y: scroll;
  .shopping-list {
    ::v-deep .van-nav-bar__content {
      background-color: #ff448f;
    }
    ::v-deep .van-nav-bar__title {
      font-size: 20px;
    }
    ::v-deep .van-button--primary {
      background-color: #ff448f;
      border: #ff448f;
    }
  }
  .shopping-con-title {
    background-color: #ff448f;
    box-sizing: border-box;
    .shopping-title {
      padding: 10px;
      height: 30px;
      display: flex;
      justify-content: space-around;
      span {
        font-size: 10px;
        color: #fff;
      }
    }
    .number {
      display: block;
      margin: 0 auto;
      border-radius: 10px 10px 0 0;
      background-color: #fff;
      width: 90%;
      height: 30px;
      padding: 15px 0 0 10px;
      b {
        font-weight: normal;
      }
      em {
        color: #ff448f;
        font-style: normal;
      }
    }
  }
  .cart-logo {
    background-color: #fff;
    padding: 40px 0;
    img {
      display: block;
      width: 207px;
      height: 167px;
      margin: 0 auto;
    }
  }
  .hot-comment {
    .hot-title {
      background-color: #fff;
      p {
        padding: 20px;
        text-align: center;
      }
    }
    .hot-display {
      background-color: #fff;
      padding: 0 10px;
      width: 100%;
      box-sizing: border-box;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      .hot-display-con {
        width: 48%;
        img {
          width: 166px;
          height: 166px;
          border-radius: 10px;
        }
        .price {
          width: 100%;
          margin: 5px 0;
          p {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            font-size: 14px;
            color: #282828;
          }
          span {
            font-weight: bolder;
            color: #ff448f;
            font-size: 14px;
            margin-bottom: 5px;
            em {
              font-size: 11px;
              font-style: normal;
              font-weight: normal;
            }
          }
        }
      }
    }
  }
}
</style>
